﻿using duia.Canteenpay.Domain.DomainObject;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;

namespace duia.Canteenpay.Repository.EntityConfiguration
{
    /// <summary>
    /// 系统用户-ef映射管理
    /// </summary>
    public class DishesEntityTypeConfiguration : BaseEntityTypeConfiguration<Dishes>
    {
        public override void Configure(EntityTypeBuilder<Dishes> builder)
        {
            builder.ToTable("canpay_dishes");
            builder.HasKey(x => x.KeyId);
            builder.Property(x => x.DishesName).IsRequired().HasMaxLength(50);
            builder.Property(x => x.DishesCode).IsRequired().HasMaxLength(50);
            builder.Property(x => x.Price).HasDefaultValue(0).HasColumnType("decimal(18,2)").IsRequired();
            builder.Property(x => x.ShowImageUrl);
            builder.Property(x => x.DishesCategoryKeyId);

            builder.HasData(AddHasData());
            base.Configure(builder);
        }

        private List<Dishes> AddHasData()
        {
            var hasData = new List<Dishes>();
            var dishesCategory = new Dishes("土豆炒猪肉", "CS1000", Guid.Parse("09f0d3c7-40fe-11eb-8fac-5254000e3ad6"), 10,
                "");
            dishesCategory.SetKeyId(Guid.NewGuid());

            hasData.Add(dishesCategory);
            return hasData;
        }
    }
}
